package models

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
	"log"
)

var db *gorm.DB
var err error

//var Redis *redis.Client

func init() {
	dsn := "root:root@tcp(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local"
	db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
		},
	})
	if err != nil {
		log.Println("数据库连接失败", err)
		return
	}
	err = db.AutoMigrate(new(User12))
	if err != nil {
		log.Println("数据表建立失败", err)
		return
	}

	//todo:连接Redis
	//Redis = redis.NewClient(&redis.Options{
	//	Addr: "localhost:6379",
	//	DB:   0,
	//})
}
